// Copyright (c) 2018 PT Defender Nusa Semesta and contributors, All rights reserved.
//
// This file is part of Dsiem.
//
// Dsiem is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// Dsiem is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Dsiem. If not, see <https://www.gnu.org/licenses/>.

package pprof

import (
	"errors"

	"github.com/pkg/profile"
)

// GetProfiler returns func to start pprof for a given profile
func GetProfiler(p string) (i interface{ Stop() }, err error) {
	switch p {
	case "cpu":
		i = profile.Start(profile.CPUProfile)
	case "memory":
		i = profile.Start(profile.MemProfile)
	case "mutex":
		i = profile.Start(profile.MutexProfile)
	case "block":
		i = profile.Start(profile.MutexProfile)
	default:
		i = nil
		err = errors.New("invalid profiler, valid option is cpu|memory|mutex|block")
	}
	return
}
